<?php

namespace app\api\model;

use app\api\service\Api;
use think\Db;
use think\Request;

class WorkCategoryModel extends Api
{
    protected static $instance;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
    }

    public static function getInstance()
    {
        if (is_null(self::$instance))
        {
            self::$instance = new static();
        }
        return self::$instance;
    }

    /**
     * 插入一条记录
     */
    public function insert($data)
    {
        Db::name('work_category')->insert($data);
        return Db::name('work_category')->getLastInsID();
    }

    /**
     * 更新一条记录
     */
    public function update($id, $data)
    {
        return Db::name('work_category')->where([
            'id' => ['eq', $id]
        ])->update($data);
    }

    /**
     * 查询一条记录
     */
    public function find($id, $field = '*')
    {
        return Db::name('work_category')->where([
            'id' => ['eq', $id]
        ])->field($field)->find();
    }

    /**
     * 查询多条记录
     */
    public function select($where, $field = '*', $start = 0, $limit = 100000)
    {
        return Db::name('work_category')->where($where)->limit($start, $limit)->order('title ASC')->field($field)->select();
    }

    /**
     * 查询记录总数
     */
    public function count($where)
    {
        return Db::name('work_category')->where($where)->count();
    }

    /**
     * 获取指定下标记录
     */
    public function column($where, $field = '*', $key = 'id')
    {
        return Db::name('work_category')->where($where)->column($field, $key);
    }
}